package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingInformation;
import com.ruoyi.teaching.service.ITeachingInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 聊天信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/information")
public class TeachingInformationController extends BaseController
{
    @Autowired
    private ITeachingInformationService teachingInformationService;

    /**
     * 查询聊天信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingInformation teachingInformation)
    {
        startPage();
        List<TeachingInformation> list = teachingInformationService.selectTeachingInformationList(teachingInformation);
        return getDataTable(list);
    }

    /**
     * 导出聊天信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:information:export')")
    @Log(title = "聊天信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingInformation teachingInformation)
    {
        List<TeachingInformation> list = teachingInformationService.selectTeachingInformationList(teachingInformation);
        ExcelUtil<TeachingInformation> util = new ExcelUtil<TeachingInformation>(TeachingInformation.class);
        util.exportExcel(response, list, "聊天信息数据");
    }

    /**
     * 获取聊天信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:information:query')")
    @GetMapping(value = "/{informationId}")
    public AjaxResult getInfo(@PathVariable("informationId") Long informationId)
    {
        return AjaxResult.success(teachingInformationService.selectTeachingInformationByInformationId(informationId));
    }

    /**
     * 新增聊天信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:information:add')")
    @Log(title = "聊天信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingInformation teachingInformation)
    {
        return toAjax(teachingInformationService.insertTeachingInformation(teachingInformation));
    }

    /**
     * 修改聊天信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:information:edit')")
    @Log(title = "聊天信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingInformation teachingInformation)
    {
        return toAjax(teachingInformationService.updateTeachingInformation(teachingInformation));
    }

    /**
     * 删除聊天信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:information:remove')")
    @Log(title = "聊天信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{informationIds}")
    public AjaxResult remove(@PathVariable Long[] informationIds)
    {
        return toAjax(teachingInformationService.deleteTeachingInformationByInformationIds(informationIds));
    }
}
